package logic

import (
	"context"
	"phone/models/mysql"

	"phone/phonerpc/internal/svc"
	"phone/phonerpc/phonerpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodAddLogic {
	return &GoodAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodAddLogic) GoodAdd(in *phonerpc.GoodAddRequest) (*phonerpc.GoodAddResponse, error) {
	// todo: add your logic here and delete this line
	good := mysql.Goods{
		UserId: int(in.UserId),
		Name:   in.Name,
	}
	mysql.DB.Debug().Create(&good)

	return &phonerpc.GoodAddResponse{
		GoodId: int64(good.ID),
	}, nil
}
